{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ca9b0eef-e64c-4f62-84c7-92f586496190",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "64c307c1-4ff0-43e0-9ba3-0caf975aab82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1    2\n",
      "2    3\n",
      "3    4\n",
      "dtype: int64\n",
      "a    1\n",
      "b    2\n",
      "c    3\n",
      "d    4\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import pandas as pd\n",
    "from pandas import Series, DataFrame\n",
    "x1 = Series([1,2,3,4])\n",
    "x2 = Series(data=[1,2,3,4], index=['a', 'b', 'c', 'd'])\n",
    "print(x1)\n",
    "print(x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "beda981d-bb8d-4702-8626-4aff8294aeae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x1.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a37ef5f7-193a-41c0-a502-53bc80747c23",
   "metadata": {},
   "outputs": [],
   "source": [
    "x3 = Series([1,None,2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4be4a7af-4b97-46e5-aee9-88f0e3a24fb5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x3.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "91059f35-56d7-4f81-bbfa-5ab56dea23e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "30b9c351-408f-4265-a30b-4af699f77a9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "torch.cuda.is_available()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "99ce64aa-1e17-4cbd-b0e4-d6b698e302e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cc4cd253-1422-421f-aef8-f34698c9afa0",
   "metadata": {},
   "outputs": [],
   "source": [
    "ts.set_token('your token here')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b94afdd6-4365-49ce-b0a7-c4ab4d24a1ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "pro = ts.pro_api()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f6a23035-42e0-4835-8fcc-6115a09cd646",
   "metadata": {},
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "抱歉，您输入的TOKEN无效！",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_14980/2245116678.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpro\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrade_cal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexchange\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m''\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstart_date\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'20180901'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend_date\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'20181001'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'exchange,cal_date,is_open,pretrade_date'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mis_open\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'0'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\miniconda3\\envs\\py397\\lib\\site-packages\\tushare\\pro\\client.py\u001b[0m in \u001b[0;36mquery\u001b[1;34m(self, api_name, fields, **kwargs)\u001b[0m\n\u001b[0;32m     42\u001b[0m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     43\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'code'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 44\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'msg'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     45\u001b[0m             \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     46\u001b[0m             \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'fields'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mException\u001b[0m: 抱歉，您输入的TOKEN无效！"
     ]
    }
   ],
   "source": [
    "df = pro.trade_cal(exchange='', start_date='20180901', end_date='20181001', fields='exchange,cal_date,is_open,pretrade_date', is_open='0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8f37f626-cd49-4472-ad93-9f34248e0b26",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1720a13e-caa7-4ebe-be28-ebe1630044e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://waditu.com/document/2\n"
     ]
    }
   ],
   "source": [
    "p = ts.get_hist_data('600848')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dbf5c2c1-63a3-4084-baed-95458c20b17f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-10-27</th>\n",
       "      <td>15.01</td>\n",
       "      <td>15.12</td>\n",
       "      <td>14.69</td>\n",
       "      <td>14.61</td>\n",
       "      <td>56733.53</td>\n",
       "      <td>-0.33</td>\n",
       "      <td>-2.20</td>\n",
       "      <td>15.050</td>\n",
       "      <td>15.186</td>\n",
       "      <td>15.187</td>\n",
       "      <td>37875.70</td>\n",
       "      <td>35113.53</td>\n",
       "      <td>36568.66</td>\n",
       "      <td>0.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-26</th>\n",
       "      <td>15.08</td>\n",
       "      <td>15.20</td>\n",
       "      <td>15.02</td>\n",
       "      <td>15.02</td>\n",
       "      <td>24291.16</td>\n",
       "      <td>-0.07</td>\n",
       "      <td>-0.46</td>\n",
       "      <td>15.164</td>\n",
       "      <td>15.253</td>\n",
       "      <td>15.212</td>\n",
       "      <td>32887.06</td>\n",
       "      <td>33759.75</td>\n",
       "      <td>36196.50</td>\n",
       "      <td>0.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-25</th>\n",
       "      <td>15.20</td>\n",
       "      <td>15.20</td>\n",
       "      <td>15.09</td>\n",
       "      <td>15.00</td>\n",
       "      <td>34938.46</td>\n",
       "      <td>-0.16</td>\n",
       "      <td>-1.05</td>\n",
       "      <td>15.204</td>\n",
       "      <td>15.265</td>\n",
       "      <td>15.215</td>\n",
       "      <td>33360.34</td>\n",
       "      <td>35534.31</td>\n",
       "      <td>36943.99</td>\n",
       "      <td>0.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-22</th>\n",
       "      <td>15.25</td>\n",
       "      <td>15.50</td>\n",
       "      <td>15.25</td>\n",
       "      <td>15.21</td>\n",
       "      <td>46717.41</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.33</td>\n",
       "      <td>15.260</td>\n",
       "      <td>15.282</td>\n",
       "      <td>15.209</td>\n",
       "      <td>32129.56</td>\n",
       "      <td>35408.76</td>\n",
       "      <td>37637.51</td>\n",
       "      <td>0.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-21</th>\n",
       "      <td>15.26</td>\n",
       "      <td>15.33</td>\n",
       "      <td>15.20</td>\n",
       "      <td>15.13</td>\n",
       "      <td>26697.95</td>\n",
       "      <td>-0.06</td>\n",
       "      <td>-0.39</td>\n",
       "      <td>15.288</td>\n",
       "      <td>15.269</td>\n",
       "      <td>15.205</td>\n",
       "      <td>30289.06</td>\n",
       "      <td>33577.26</td>\n",
       "      <td>37808.79</td>\n",
       "      <td>0.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-05-08</th>\n",
       "      <td>28.58</td>\n",
       "      <td>30.57</td>\n",
       "      <td>29.74</td>\n",
       "      <td>28.48</td>\n",
       "      <td>97879.09</td>\n",
       "      <td>-0.49</td>\n",
       "      <td>-1.62</td>\n",
       "      <td>32.154</td>\n",
       "      <td>32.154</td>\n",
       "      <td>32.154</td>\n",
       "      <td>127608.89</td>\n",
       "      <td>127608.89</td>\n",
       "      <td>127608.89</td>\n",
       "      <td>1.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-05-07</th>\n",
       "      <td>31.00</td>\n",
       "      <td>31.70</td>\n",
       "      <td>30.23</td>\n",
       "      <td>28.73</td>\n",
       "      <td>157289.84</td>\n",
       "      <td>-1.47</td>\n",
       "      <td>-4.64</td>\n",
       "      <td>32.758</td>\n",
       "      <td>32.758</td>\n",
       "      <td>32.758</td>\n",
       "      <td>135041.34</td>\n",
       "      <td>135041.34</td>\n",
       "      <td>135041.34</td>\n",
       "      <td>2.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-05-06</th>\n",
       "      <td>32.03</td>\n",
       "      <td>33.18</td>\n",
       "      <td>31.70</td>\n",
       "      <td>31.70</td>\n",
       "      <td>112336.46</td>\n",
       "      <td>-3.52</td>\n",
       "      <td>-9.99</td>\n",
       "      <td>33.600</td>\n",
       "      <td>33.600</td>\n",
       "      <td>33.600</td>\n",
       "      <td>127625.17</td>\n",
       "      <td>127625.17</td>\n",
       "      <td>127625.17</td>\n",
       "      <td>1.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-30</th>\n",
       "      <td>33.80</td>\n",
       "      <td>35.55</td>\n",
       "      <td>35.22</td>\n",
       "      <td>33.50</td>\n",
       "      <td>113277.15</td>\n",
       "      <td>1.34</td>\n",
       "      <td>3.96</td>\n",
       "      <td>34.550</td>\n",
       "      <td>34.550</td>\n",
       "      <td>34.550</td>\n",
       "      <td>135269.52</td>\n",
       "      <td>135269.52</td>\n",
       "      <td>135269.52</td>\n",
       "      <td>1.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-29</th>\n",
       "      <td>33.70</td>\n",
       "      <td>35.22</td>\n",
       "      <td>33.88</td>\n",
       "      <td>33.61</td>\n",
       "      <td>157261.89</td>\n",
       "      <td>0.73</td>\n",
       "      <td>2.20</td>\n",
       "      <td>33.880</td>\n",
       "      <td>33.880</td>\n",
       "      <td>33.880</td>\n",
       "      <td>157261.89</td>\n",
       "      <td>157261.89</td>\n",
       "      <td>157261.89</td>\n",
       "      <td>2.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>606 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low     volume  price_change  p_change  \\\n",
       "date                                                                        \n",
       "2021-10-27  15.01  15.12  14.69  14.61   56733.53         -0.33     -2.20   \n",
       "2021-10-26  15.08  15.20  15.02  15.02   24291.16         -0.07     -0.46   \n",
       "2021-10-25  15.20  15.20  15.09  15.00   34938.46         -0.16     -1.05   \n",
       "2021-10-22  15.25  15.50  15.25  15.21   46717.41          0.05      0.33   \n",
       "2021-10-21  15.26  15.33  15.20  15.13   26697.95         -0.06     -0.39   \n",
       "...           ...    ...    ...    ...        ...           ...       ...   \n",
       "2019-05-08  28.58  30.57  29.74  28.48   97879.09         -0.49     -1.62   \n",
       "2019-05-07  31.00  31.70  30.23  28.73  157289.84         -1.47     -4.64   \n",
       "2019-05-06  32.03  33.18  31.70  31.70  112336.46         -3.52     -9.99   \n",
       "2019-04-30  33.80  35.55  35.22  33.50  113277.15          1.34      3.96   \n",
       "2019-04-29  33.70  35.22  33.88  33.61  157261.89          0.73      2.20   \n",
       "\n",
       "               ma5    ma10    ma20      v_ma5     v_ma10     v_ma20  turnover  \n",
       "date                                                                           \n",
       "2021-10-27  15.050  15.186  15.187   37875.70   35113.53   36568.66      0.39  \n",
       "2021-10-26  15.164  15.253  15.212   32887.06   33759.75   36196.50      0.17  \n",
       "2021-10-25  15.204  15.265  15.215   33360.34   35534.31   36943.99      0.24  \n",
       "2021-10-22  15.260  15.282  15.209   32129.56   35408.76   37637.51      0.32  \n",
       "2021-10-21  15.288  15.269  15.205   30289.06   33577.26   37808.79      0.18  \n",
       "...            ...     ...     ...        ...        ...        ...       ...  \n",
       "2019-05-08  32.154  32.154  32.154  127608.89  127608.89  127608.89      1.24  \n",
       "2019-05-07  32.758  32.758  32.758  135041.34  135041.34  135041.34      2.00  \n",
       "2019-05-06  33.600  33.600  33.600  127625.17  127625.17  127625.17      1.43  \n",
       "2019-04-30  34.550  34.550  34.550  135269.52  135269.52  135269.52      1.44  \n",
       "2019-04-29  33.880  33.880  33.880  157261.89  157261.89  157261.89      2.00  \n",
       "\n",
       "[606 rows x 14 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1884752a-913f-480b-8c77-69083bd7e33b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
